package com.ruoyi.web.controller.money;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.money.domain.CommunityPayment;
import com.ruoyi.money.service.ICommunityPaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线缴费Controller
 *
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/money/payment")
public class CommunityPaymentController extends BaseController
{
    @Autowired
    private ICommunityPaymentService communityPaymentService;

    /**
     * 查询在线缴费列表
     */
    @PreAuthorize("@ss.hasPermi('money:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityPayment communityPayment)
    {
        startPage();
        List<CommunityPayment> list = communityPaymentService.selectCommunityPaymentList(communityPayment);
        return getDataTable(list);
    }

    /**
     * 导出在线缴费列表
     */
    @PreAuthorize("@ss.hasPermi('money:payment:export')")
    @Log(title = "在线缴费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityPayment communityPayment)
    {
        List<CommunityPayment> list = communityPaymentService.selectCommunityPaymentList(communityPayment);
        ExcelUtil<CommunityPayment> util = new ExcelUtil<CommunityPayment>(CommunityPayment.class);
        util.exportExcel(response, list, "在线缴费数据");
    }

    /**
     * 获取在线缴费详细信息
     */
    @PreAuthorize("@ss.hasPermi('money:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityPaymentService.selectCommunityPaymentById(id));
    }

    /**
     * 新增在线缴费
     */
    @PreAuthorize("@ss.hasPermi('money:payment:add')")
    @Log(title = "在线缴费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityPayment communityPayment)
    {
        return toAjax(communityPaymentService.insertCommunityPayment(communityPayment));
    }

    /**
     * 修改在线缴费
     */
    @PreAuthorize("@ss.hasPermi('money:payment:edit')")
    @Log(title = "在线缴费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityPayment communityPayment) {
        return toAjax(communityPaymentService.updateCommunityPayment(communityPayment));
    }

    /**
     * 删除在线缴费
     */
    @PreAuthorize("@ss.hasPermi('money:payment:remove')")
    @Log(title = "在线缴费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityPaymentService.deleteCommunityPaymentByIds(ids));
    }
}
